﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using Wedn.Core.Utility;

namespace Wedn.Web.UI.Admin.Handler
{
    /// <summary>
    /// file_delete 的摘要说明
    /// </summary>
    public class FileDelete : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string path = RequestHelper.QueryString("path", true);
            if (string.IsNullOrEmpty(path) || !path.Contains("upload"))
                context.Response.End();
            try
            {
                if (path.EndsWith("/"))
                {
                    Directory.Delete(context.Server.MapPath(path), true);
                    context.Response.Write("success");
                }
                else
                {
                    File.Delete(context.Server.MapPath(path));
                    context.Response.Write("success");
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.Message);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}